package com.king.platform.entity;

import com.king.platform.enmu.ResultEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class BaseResult<T>
{
  private int code;

  private String message;

  private Integer status;

  private T data;

  public BaseResult(int code, String message, Integer status)
  {
    this.code = code;
    this.message = message;
    this.status = status;
  }

  public BaseResult(int code, String message, Integer status, T data)
  {
    this.code = code;
    this.message = message;
    this.status = status;
    this.data = data;
  }


  public BaseResult(ResultEnum result, Integer status, T data)
  {
    this.code = result.getCode();
    this.message = result.getMessage();
    this.status = status;
    this.data = data;
  }

  public static <T> BaseResult<T> success(int code, String message)
  {
    return new BaseResult<>(code, message, code);
  }

  public static <T> BaseResult<T> success(ResultEnum result)
  {
    return new BaseResult<>(result.getCode(), result.getMessage(), result.getCode());
  }

  public static <T> BaseResult<T> success(ResultEnum result, T data)
  {
    return new BaseResult<>(result.getCode(), result.getMessage(), result.getCode(), data);
  }

  public static <T> BaseResult<T> failed(int code, String message)
  {
    return new BaseResult<>(code, message, code);
  }

  public static <T> BaseResult<T> failed(ResultEnum result)
  {
    return new BaseResult<>(result.getCode(), result.getMessage(), result.getCode());
  }

  public static <T> BaseResult<T> failed(ResultEnum result, T data)
  {
    return new BaseResult<>(result.getCode(), result.getMessage(), result.getCode(), data);
  }
}
